/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.evl.tecinfo.gui;

import java.awt.Color;
import javax.swing.JOptionPane;

/**
 *
 * @author Tecinfo
 */
public class EditarCargo extends javax.swing.JFrame {

    private int clicou_ok;
    private int linha_editar = -1;

    /**
     * Creates new form editar_cargo
     */
    public EditarCargo() {
        initComponents();
        setResizable(false);
        setTitle("Editar Cargo");
        setSize(527, 448);
        setLocationRelativeTo(this);



    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelEditarCargo = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable_editarcargo = new javax.swing.JTable();
        jFormattedTextField_Nome = new javax.swing.JFormattedTextField();
        jLabelNomeArea = new javax.swing.JLabel();
        jLabelNumeroArea = new javax.swing.JLabel();
        jSpinnerNumeroArea = new javax.swing.JSpinner();
        jButtonEditArea = new javax.swing.JButton();
        jButtonRemoverArea = new javax.swing.JButton();
        jButtonSalvarArea = new javax.swing.JButton();
        jButtonCancelarArea = new javax.swing.JButton();
        jLabel_IMG_Cima = new javax.swing.JLabel();
        jLabel_IMG_Baixo = new javax.swing.JLabel();
        jLabel_IMG_Esquerda = new javax.swing.JLabel();
        jLabel_IMG_Direito = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabelIMGEditarcargo = new javax.swing.JLabel();
        jLabelIMGBackgroudCargo = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabelEditarCargo.setFont(new java.awt.Font("Century Gothic", 0, 15)); // NOI18N
        jLabelEditarCargo.setForeground(new java.awt.Color(102, 102, 102));
        jLabelEditarCargo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelEditarCargo.setText("EDITAR CARGO");
        getContentPane().add(jLabelEditarCargo);
        jLabelEditarCargo.setBounds(180, 10, 160, 50);

        jTable_editarcargo.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome", "Número"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable_editarcargo);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(20, 250, 480, 150);

        jFormattedTextField_Nome.setEnabled(false);
        getContentPane().add(jFormattedTextField_Nome);
        jFormattedTextField_Nome.setBounds(250, 120, 250, 30);

        jLabelNomeArea.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        jLabelNomeArea.setText("Nome:");
        jLabelNomeArea.setEnabled(false);
        getContentPane().add(jLabelNomeArea);
        jLabelNomeArea.setBounds(200, 120, 39, 30);

        jLabelNumeroArea.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        jLabelNumeroArea.setText("Número:");
        jLabelNumeroArea.setEnabled(false);
        getContentPane().add(jLabelNumeroArea);
        jLabelNumeroArea.setBounds(30, 120, 50, 25);

        jSpinnerNumeroArea.setModel(new javax.swing.SpinnerNumberModel(0, 0, 10, 1));
        jSpinnerNumeroArea.setEnabled(false);
        getContentPane().add(jSpinnerNumeroArea);
        jSpinnerNumeroArea.setBounds(90, 120, 90, 30);

        jButtonEditArea.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        jButtonEditArea.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/editarrelatorio20x20.png"))); // NOI18N
        jButtonEditArea.setText("EDITAR");
        jButtonEditArea.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jButtonEditArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditAreaActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonEditArea);
        jButtonEditArea.setBounds(20, 190, 100, 30);

        jButtonRemoverArea.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        jButtonRemoverArea.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/excluirrelatorio20x20.png"))); // NOI18N
        jButtonRemoverArea.setText("REMOVER");
        jButtonRemoverArea.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jButtonRemoverArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRemoverAreaActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonRemoverArea);
        jButtonRemoverArea.setBounds(130, 190, 120, 30);

        jButtonSalvarArea.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        jButtonSalvarArea.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/salvar20x20.png"))); // NOI18N
        jButtonSalvarArea.setText("SALVAR");
        jButtonSalvarArea.setEnabled(false);
        jButtonSalvarArea.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jButtonSalvarArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSalvarAreaActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonSalvarArea);
        jButtonSalvarArea.setBounds(260, 190, 110, 30);

        jButtonCancelarArea.setFont(new java.awt.Font("Century Gothic", 0, 11)); // NOI18N
        jButtonCancelarArea.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/sair20x20.png"))); // NOI18N
        jButtonCancelarArea.setText("CANCELAR");
        jButtonCancelarArea.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jButtonCancelarArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarAreaActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonCancelarArea);
        jButtonCancelarArea.setBounds(380, 190, 120, 30);

        jLabel_IMG_Cima.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/backgroudlado - CIMA.jpg"))); // NOI18N
        getContentPane().add(jLabel_IMG_Cima);
        jLabel_IMG_Cima.setBounds(-6, 70, 540, 10);

        jLabel_IMG_Baixo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/backgroudlado - CIMA.jpg"))); // NOI18N
        getContentPane().add(jLabel_IMG_Baixo);
        jLabel_IMG_Baixo.setBounds(0, 180, 530, 50);

        jLabel_IMG_Esquerda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/abamenu.jpg"))); // NOI18N
        getContentPane().add(jLabel_IMG_Esquerda);
        jLabel_IMG_Esquerda.setBounds(-10, 70, 20, 110);

        jLabel_IMG_Direito.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/abamenu.jpg"))); // NOI18N
        getContentPane().add(jLabel_IMG_Direito);
        jLabel_IMG_Direito.setBounds(510, 80, 20, 110);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/registro.jpg"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(0, 80, 530, 110);

        jLabelIMGEditarcargo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/CADASTRODEUSUARIO.png"))); // NOI18N
        getContentPane().add(jLabelIMGEditarcargo);
        jLabelIMGEditarcargo.setBounds(160, 10, 210, 50);

        jLabelIMGBackgroudCargo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/evl/tecinfo/gui/imagens/backgroud.jpg"))); // NOI18N
        getContentPane().add(jLabelIMGBackgroudCargo);
        jLabelIMGBackgroudCargo.setBounds(0, 0, 520, 420);

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonEditAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEditAreaActionPerformed
        // TODO add your handling code here:
        jLabelNumeroArea.setEnabled(true);
        jLabelNomeArea.setEnabled(true);
        jFormattedTextField_Nome.setEnabled(true);
        jSpinnerNumeroArea.setEnabled(true);
        jButtonSalvarArea.setEnabled(true);
        jButtonRemoverArea.setEnabled(false);

    }//GEN-LAST:event_jButtonEditAreaActionPerformed

    private void jButtonSalvarAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSalvarAreaActionPerformed
        // TODO add your handling code here:
        boolean spinervazios = false;
        boolean nomevazio = false;
        if (linha_editar == -1) {
            if (jSpinnerNumeroArea.getValue() == 0) {
                spinervazios = true;
            } else {
                spinervazios = false;
            }
            if (jFormattedTextField_Nome.getText().equals("")) {
                jFormattedTextField_Nome.setBackground(new Color(255, 209, 209));
                nomevazio = true;
            } else {
                jFormattedTextField_Nome.setBackground(new Color(255, 255, 255));
                nomevazio = false;
            }
            if (spinervazios == false && nomevazio == false) {

                // EDITADO!!!

                jFormattedTextField_Nome.setText("");
                jSpinnerNumeroArea.setValue(0);
                jLabelNumeroArea.setEnabled(false);
                jLabelNomeArea.setEnabled(false);
                jFormattedTextField_Nome.setEnabled(false);
                jSpinnerNumeroArea.setEnabled(false);
                jButtonSalvarArea.setEnabled(false);
                jButtonRemoverArea.setEnabled(true);

            } else {
                java.awt.Toolkit.getDefaultToolkit().beep();
                java.awt.Toolkit.getDefaultToolkit().beep();
                JOptionPane.showMessageDialog(null, "Por favor, preencha os campos vazios!");
            }
        }
    }//GEN-LAST:event_jButtonSalvarAreaActionPerformed

    private void jButtonCancelarAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarAreaActionPerformed
        clicou_ok = JOptionPane.showConfirmDialog(null, "Deseja cancelar?", "Confirmação", JOptionPane.YES_NO_OPTION);
        if (clicou_ok == JOptionPane.YES_OPTION) {
            this.dispose();
        } else if (clicou_ok == JOptionPane.NO_OPTION) {
        }
    }//GEN-LAST:event_jButtonCancelarAreaActionPerformed

    private void jButtonRemoverAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemoverAreaActionPerformed
        if (jTable_editarcargo.getSelectedRowCount() != 0) {
            clicou_ok = JOptionPane.showConfirmDialog(null, "Tem certeza que deseja deletar esse Cargo?", "Confirmação", JOptionPane.YES_NO_OPTION);
            if (clicou_ok == JOptionPane.YES_OPTION) {
            } else if (clicou_ok == JOptionPane.NO_OPTION) {
            }
        } else {
            java.awt.Toolkit.getDefaultToolkit().beep();
            JOptionPane.showMessageDialog(null, "Por favor selecione uma linha da tabela");
        }
    }//GEN-LAST:event_jButtonRemoverAreaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EditarCargo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EditarCargo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EditarCargo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EditarCargo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new EditarCargo().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancelarArea;
    private javax.swing.JButton jButtonEditArea;
    private javax.swing.JButton jButtonRemoverArea;
    private javax.swing.JButton jButtonSalvarArea;
    private javax.swing.JFormattedTextField jFormattedTextField_Nome;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelEditarCargo;
    private javax.swing.JLabel jLabelIMGBackgroudCargo;
    private javax.swing.JLabel jLabelIMGEditarcargo;
    private javax.swing.JLabel jLabelNomeArea;
    private javax.swing.JLabel jLabelNumeroArea;
    private javax.swing.JLabel jLabel_IMG_Baixo;
    private javax.swing.JLabel jLabel_IMG_Cima;
    private javax.swing.JLabel jLabel_IMG_Direito;
    private javax.swing.JLabel jLabel_IMG_Esquerda;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSpinner jSpinnerNumeroArea;
    private javax.swing.JTable jTable_editarcargo;
    // End of variables declaration//GEN-END:variables
}
